package xyz.syyrjx.blog.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.dom4j.DocumentException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import xyz.syyrjx.blog.dao.site.UrlSendDao;
import xyz.syyrjx.blog.entity.site.UrlSend;
import xyz.syyrjx.blog.service.SiteSubmitService;
import xyz.syyrjx.blog.util.site.BaiduSubmitUtil;
import xyz.syyrjx.blog.util.site.SiteSubmitUtil;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 大地崩坏苍蝇兽
 * @date 2024/2/20 15:29
 * @description ...
 * @since v0.0.1
 */
@Service
public class SiteSubmitServiceImpl implements SiteSubmitService {

    @Resource
    private BaiduSubmitUtil baiduSubmitUtil;

    @Resource
    private UrlSendDao urlSendDao;

    @Override
    public String submitService(String which) throws DocumentException, JsonProcessingException {
        SiteSubmitUtil siteSubmitUtil = null;
        switch (which) {
            case "baidu":
                siteSubmitUtil = baiduSubmitUtil;
                break;
            default:
                return "没有这个选项";
        }
        List<UrlSend> urlSends = urlSendDao.selectAllUrlSend();
        List<String> successUrls = siteSubmitUtil.submit(urlSends);
        for (String successUrl : successUrls) {
            urlSendDao.insertUrl(successUrl);
        }
        return "插入成功的url有：" + successUrls;
    }
}
